package de.fhkl.gatav.ut.bernd_1;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class BerndActivity extends Activity {
	private MediaPlayer mPlayer;
    private ImageView bernd;
    private Animation drop;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        bernd = (ImageView) findViewById(R.id.berndView);
        drop = AnimationUtils.loadAnimation(this, R.anim.falldown);
        
// Sound
        mPlayer = MediaPlayer.create(this, R.raw.berndsaahhh);
        mPlayer.setLooping(false);

// Redo durch click auf Bernd        
        ImageView berndTheButton = (ImageView) findViewById(R.id.berndView);
        berndTheButton.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		mPlayer.stop();
        		try {
        			mPlayer.prepare();
        		} catch (IllegalStateException e) {
        			// TODO Auto-generated catch block
        			e.printStackTrace();
        		} catch (IOException e) {
        			// TODO Auto-generated catch block
        			e.printStackTrace();
        		}
        		startFalling();
        	}
        } );

// Und ab geht die Post        
        startFalling();
    }
    
    private void startFalling () {

// Ohne Sound die folgende Zeile erst mal raus    	
    	mPlayer.start();
        bernd.startAnimation(drop);    	
    }
}